
 <!DOCTYPE HTML>
<html >
<head>
  <meta charset="UTF-8">
  
    <title>吴朝捷_文件处理模块算法 | B3434lockchain</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=no">
    
    <meta name="author" content="b3434lockchain">
    

    
    <meta name="description" content="实验目的这（week1中的流程）没有什么实战教程，都是自己构建，不过你可以上github都是可以找到相关的实现代码的，你可以按照以下步骤来进行1）简单的对称加密算法对文件进行加密解密2）哈希算法计算文件哈希值3）用文件切割算法对文件进行碎片化4）利用切割完的碎片计算碎片哈希值，再利用这些哈希值构造Merkle树   这就把总体任务先分成几个小的任务，先把小任务完成在组合起来（也就是week1中提到">
<meta name="keywords" content="报告,吴朝捷">
<meta property="og:type" content="article">
<meta property="og:title" content="吴朝捷_文件处理模块算法">
<meta property="og:url" content="http://b3434lockchain.gitee.io/2019/06/04/wuchaojie/wuchaojie2/index.html">
<meta property="og:site_name" content="B3434lockchain">
<meta property="og:description" content="实验目的这（week1中的流程）没有什么实战教程，都是自己构建，不过你可以上github都是可以找到相关的实现代码的，你可以按照以下步骤来进行1）简单的对称加密算法对文件进行加密解密2）哈希算法计算文件哈希值3）用文件切割算法对文件进行碎片化4）利用切割完的碎片计算碎片哈希值，再利用这些哈希值构造Merkle树   这就把总体任务先分成几个小的任务，先把小任务完成在组合起来（也就是week1中提到">
<meta property="og:locale" content="default">
<meta property="og:image" content="https://i.imgur.com/qGvX42N.png">
<meta property="og:image" content="https://i.imgur.com/RbDtuCi.png">
<meta property="og:updated_time" content="2019-06-04T15:52:45.607Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="吴朝捷_文件处理模块算法">
<meta name="twitter:description" content="实验目的这（week1中的流程）没有什么实战教程，都是自己构建，不过你可以上github都是可以找到相关的实现代码的，你可以按照以下步骤来进行1）简单的对称加密算法对文件进行加密解密2）哈希算法计算文件哈希值3）用文件切割算法对文件进行碎片化4）利用切割完的碎片计算碎片哈希值，再利用这些哈希值构造Merkle树   这就把总体任务先分成几个小的任务，先把小任务完成在组合起来（也就是week1中提到">
<meta name="twitter:image" content="https://i.imgur.com/qGvX42N.png">

    
    <link rel="alternative" href="/atom.xml" title="B3434lockchain" type="application/atom+xml">
    
    
    <link rel="icon" href="/img/favicon.ico">
    
    
    <link rel="apple-touch-icon" href="/img/jacman.jpg">
    <link rel="apple-touch-icon-precomposed" href="/img/jacman.jpg">
    
    <link rel="stylesheet" href="/css/style.css">
</head>

  <body>
    <header>
      
<div>
		
			<div id="imglogo">
				<a href="/"><img src="/img/logo.png" alt="B3434lockchain" title="B3434lockchain"/></a>
			</div>
			
			<div id="textlogo">
				<h1 class="site-name"><a href="/" title="B3434lockchain">B3434lockchain</a></h1>
				<h2 class="blog-motto"></h2>
			</div>
			<div class="navbar"><a class="navbutton navmobile" href="#" title="Menu">
			</a></div>
			<nav class="animated">
				<ul>
					<ul>
					 
						<li><a href="/">Home</a></li>
					
						<li><a href="/archives">Archives</a></li>
					
						<li><a href="/about">About</a></li>
					
					<li>
 					
						<form class="search" action="https://www.baidu.com" target="_blank">
							<label>Search</label>
						<input name="s" type="hidden" value=  ><input type="text" name="q" size="30" placeholder="Search"><br>
						</form>
					
					</li>
				</ul>
			</nav>			
</div>
    </header>
    <div id="container">
      <div id="main" class="post" itemscope itemprop="blogPost">
  
	<article itemprop="articleBody"> 
		<header class="article-info clearfix">
  <h1 itemprop="name">
    
      <a href="/2019/06/04/wuchaojie/wuchaojie2/" title="吴朝捷_文件处理模块算法" itemprop="url">吴朝捷_文件处理模块算法</a>
  </h1>
  <p class="article-author">By
       
		<a href="/about" title="b3434lockchain" target="_blank" itemprop="author">b3434lockchain</a>
		
  <p class="article-time">
    <time datetime="2019-06-03T16:00:00.000Z" itemprop="datePublished"> Published 2019-06-04</time>
    
  </p>
</header>
	<div class="article-content">
		
		<div id="toc" class="toc-article">
			<strong class="toc-title">Contents</strong>
		
			<ol class="toc"><li class="toc-item toc-level-5"><a class="toc-link" href="#实验目的"><span class="toc-number">1.</span> <span class="toc-text">实验目的</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#实验原理"><span class="toc-number">2.</span> <span class="toc-text">实验原理</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#实验内容"><span class="toc-number">3.</span> <span class="toc-text">实验内容</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#总结"><span class="toc-number">4.</span> <span class="toc-text">总结</span></a></li></ol>
		
		</div>
		
		<h5 id="实验目的"><a href="#实验目的" class="headerlink" title="实验目的"></a>实验目的</h5><p>这（week1中的流程）没有什么实战教程，都是自己构建，不过你可以上github都是可以找到相关的实现代码的，你可以按照以下步骤来进行<br>1）简单的对称加密算法对文件进行加密解密<br>2）哈希算法计算文件哈希值<br>3）用文件切割算法对文件进行碎片化<br>4）利用切割完的碎片计算碎片哈希值，再利用这些哈希值构造Merkle树  </p>
<p>这就把总体任务先分成几个小的任务，先把小任务完成在组合起来（也就是week1中提到的）：</p>
<blockquote>
<p>· 就是当选择一个文件的时候，你需要对该文件进行加密（对称加密算法、DCP-ABE)<br>· 并对密文进行分割成碎片，并利用merkle树结构来记录对应信息以便后续检验。<br>· 当一个碎片被篡改之后，你可以利用记录下来的merkle树的信息检测出来</p>
</blockquote>
<h5 id="实验原理"><a href="#实验原理" class="headerlink" title="实验原理"></a>实验原理</h5><p>1.哈希算法</p>
<blockquote>
<p>参考文章 《Hash算法总结》<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&gt;https://blog.csdn.net/asdzheng/article/details/70226007</span><br><span class="line">&gt;</span><br></pre></td></tr></table></figure></p>
</blockquote>
<p>①哈希算法的定义和作用</p>
<p>可以将“文件”和“哈希值”类比为“人”和“指纹”的关系。使用哈希算法的目的就是用特定的哈希值来“代表”某个特定的文件，以减少系统开销。而哈希算法的一种定义是：</p>
<blockquote>
<p>哈希算法：是一种从任意文件中创造小的数字「指纹」的方法。与指纹一样，散列算法就是一种以较短的信息来保证文件唯一性的标志，这种标志与文件的每一个字节都相关，而且难以找到逆向规律。因此，当原有文件发生改变时，其标志值也会发生改变，从而告诉文件使用者当前的文件已经不是你所需求的文件。</p>
</blockquote>
<p>②哈希算法的特点</p>
<blockquote>
<ol>
<li>正向快速：给定明文和 hash 算法，在有限时间和有限资源内能计算出 hash 值。  </li>
<li>逆向困难：给定（若干） hash 值，在有限时间内很难（基本不可能）逆推出明文。  </li>
<li>输入敏感：原始输入信息修改一点信息，产生的 hash 值看起来应该都有很大不同。  </li>
<li>冲突避免：很难找到两段内容不同的明文，使得它们的 hash 值一致（发生冲突）。即对于任意两个不同的数据块，其hash值相同的可能性极小；对于一个给定的数据块，找到和它hash值相同的数据块极为困难。</li>
</ol>
</blockquote>
<p>③常用的哈希算法</p>
<p>主要有MD5、SHA-1、SHA-2  </p>
<p>2.文件切割</p>
<p>就是把较大文件，分割成若干小文件，然后还能合起来。所以实际上是包括 切割-合并 两个内容。</p>
<h5 id="实验内容"><a href="#实验内容" class="headerlink" title="实验内容"></a>实验内容</h5><p>1.对称加密算法的实现</p>
<p>eclipse环境jar包导入问题还是没解决……改用了InteliJ IDE。采用的代码也和week1中提到的有所不同。</p>
<p>实验结果如下图所示<br><img src="https://i.imgur.com/qGvX42N.png" alt=""></p>
<p>DES代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br></pre></td><td class="code"><pre><span class="line">import java.security.Key;</span><br><span class="line">import javax.crypto.Cipher;</span><br><span class="line">import javax.crypto.KeyGenerator;</span><br><span class="line">import javax.crypto.SecretKey;</span><br><span class="line">import javax.crypto.SecretKeyFactory;</span><br><span class="line">import javax.crypto.spec.DESKeySpec;</span><br><span class="line">import org.apache.commons.codec.binary.Base64;</span><br><span class="line">/**</span><br><span class="line"> * DES对称加密算法</span><br><span class="line"> * @author kongqz</span><br><span class="line"> * */</span><br><span class="line">public class DESCoder &#123;</span><br><span class="line">	/**</span><br><span class="line">	 * 密钥算法</span><br><span class="line">	 * java支持56位密钥，bouncycastle支持64位</span><br><span class="line">	 * */</span><br><span class="line">	public static final String KEY_ALGORITHM=&quot;DES&quot;;</span><br><span class="line">	</span><br><span class="line">	/**</span><br><span class="line">	 * 加密/解密算法/工作模式/填充方式</span><br><span class="line">	 * */</span><br><span class="line">	public static final String CIPHER_ALGORITHM=&quot;DES/ECB/PKCS5Padding&quot;;</span><br><span class="line">	</span><br><span class="line">	/**</span><br><span class="line">	 * </span><br><span class="line">	 * 生成密钥，java6只支持56位密钥，bouncycastle支持64位密钥</span><br><span class="line">	 * @return byte[] 二进制密钥</span><br><span class="line">	 * */</span><br><span class="line">	public static byte[] initkey() throws Exception&#123;</span><br><span class="line">		</span><br><span class="line">		//实例化密钥生成器</span><br><span class="line">		KeyGenerator kg=KeyGenerator.getInstance(KEY_ALGORITHM);</span><br><span class="line">		//初始化密钥生成器</span><br><span class="line">		kg.init(56);</span><br><span class="line">		//生成密钥</span><br><span class="line">		SecretKey secretKey=kg.generateKey();</span><br><span class="line">		//获取二进制密钥编码形式</span><br><span class="line">		return secretKey.getEncoded();</span><br><span class="line">	&#125;</span><br><span class="line">	/**</span><br><span class="line">	 * 转换密钥</span><br><span class="line">	 * @param key 二进制密钥</span><br><span class="line">	 * @return Key 密钥</span><br><span class="line">	 * */</span><br><span class="line">	public static Key toKey(byte[] key) throws Exception&#123;</span><br><span class="line">		//实例化Des密钥</span><br><span class="line">		DESKeySpec dks=new DESKeySpec(key);</span><br><span class="line">		//实例化密钥工厂</span><br><span class="line">		SecretKeyFactory keyFactory=SecretKeyFactory.getInstance(KEY_ALGORITHM);</span><br><span class="line">		//生成密钥</span><br><span class="line">		SecretKey secretKey=keyFactory.generateSecret(dks);</span><br><span class="line">		return secretKey;</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	/**</span><br><span class="line">	 * 加密数据</span><br><span class="line">	 * @param data 待加密数据</span><br><span class="line">	 * @param key 密钥</span><br><span class="line">	 * @return byte[] 加密后的数据</span><br><span class="line">	 * */</span><br><span class="line">	public static byte[] encrypt(byte[] data,byte[] key) throws Exception&#123;</span><br><span class="line">		//还原密钥</span><br><span class="line">		Key k=toKey(key);</span><br><span class="line">		//实例化</span><br><span class="line">		Cipher cipher=Cipher.getInstance(CIPHER_ALGORITHM);</span><br><span class="line">		//初始化，设置为加密模式</span><br><span class="line">		cipher.init(Cipher.ENCRYPT_MODE, k);</span><br><span class="line">		//执行操作</span><br><span class="line">		return cipher.doFinal(data);</span><br><span class="line">	&#125;</span><br><span class="line">	/**</span><br><span class="line">	 * 解密数据</span><br><span class="line">	 * @param data 待解密数据</span><br><span class="line">	 * @param key 密钥</span><br><span class="line">	 * @return byte[] 解密后的数据</span><br><span class="line">	 * */</span><br><span class="line">	public static byte[] decrypt(byte[] data,byte[] key) throws Exception&#123;</span><br><span class="line">		//欢迎密钥</span><br><span class="line">		Key k =toKey(key);</span><br><span class="line">		//实例化</span><br><span class="line">		Cipher cipher=Cipher.getInstance(CIPHER_ALGORITHM);</span><br><span class="line">		//初始化，设置为解密模式</span><br><span class="line">		cipher.init(Cipher.DECRYPT_MODE, k);</span><br><span class="line">		//执行操作</span><br><span class="line">		return cipher.doFinal(data);</span><br><span class="line">	&#125;</span><br><span class="line">	/**</span><br><span class="line">	 * @param args</span><br><span class="line">	 * @throws Exception </span><br><span class="line">	 */</span><br><span class="line">	public static void main(String[] args) throws Exception &#123;</span><br><span class="line">		String str=&quot;DES&quot;;</span><br><span class="line">		System.out.println(&quot;原文：&quot;+str);</span><br><span class="line">		//初始化密钥</span><br><span class="line">		byte[] key=DESCoder.initkey();</span><br><span class="line">		System.out.println(&quot;密钥：&quot;+Base64.encodeBase64String(key));</span><br><span class="line">		//加密数据</span><br><span class="line">		byte[] data=DESCoder.encrypt(str.getBytes(), key);</span><br><span class="line">		System.out.println(&quot;加密后：&quot;+Base64.encodeBase64String(data));</span><br><span class="line">		//解密数据</span><br><span class="line">		data=DESCoder.decrypt(data, key);</span><br><span class="line">		System.out.println(&quot;解密后：&quot;+new String(data));</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>2.哈希算法实现-MD5</p>
<blockquote>
<p>参考文章《JAVA中获取文件MD5值的四种方法》<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&gt;https://blog.csdn.net/kongqz/article/details/6284728</span><br><span class="line">&gt;</span><br></pre></td></tr></table></figure></p>
</blockquote>
<p>尝试了一下第一种实现方法，但好像没输出，还要在研究一下<br>①代码：</p>
<pre><code>import java.io.File;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.apache.commons.io.FileUtils;

public class test {

    private final static String[] strHex = { &quot;0&quot;, &quot;1&quot;, &quot;2&quot;, &quot;3&quot;, &quot;4&quot;, &quot;5&quot;,&quot;6&quot;, &quot;7&quot;, &quot;8&quot;, &quot;9&quot;, &quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;, &quot;f&quot; };

    public static String getMD5One(String path) {
        StringBuffer sb = new StringBuffer();
        try {
            MessageDigest md = MessageDigest.getInstance(&quot;MD5&quot;);
            byte[] b = md.digest(FileUtils.readFileToByteArray(new File(path)));
            for (int i = 0; i &lt; b.length; i++) {
                int d = b[i];
                if (d &lt; 0) {
                    d += 256;
                }
                int d1 = d / 16;
                int d2 = d % 16;
                sb.append(strHex[d1] + strHex[d2]);
            }
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return sb.toString();
    }

    public static void main(String[] args){
        test.getMD5One(&quot;D:\\test.txt&quot;);
    }
}

</code></pre><p>②代码输出：<br><img src="https://i.imgur.com/RbDtuCi.png" alt=""></p>
<p>3.文件切割算法</p>
<p>先码住了两篇文章，都给出了代码，但好像只能对某种格式的文件（二进制，txt）进行分割，还没细看</p>
<p>代码实现：</p>
<blockquote>
<p><a href="https://blog.csdn.net/kevin_Luan/article/details/7903389（二进制文件，text文件）" target="_blank" rel="noopener">https://blog.csdn.net/kevin_Luan/article/details/7903389（二进制文件，text文件）</a><br><a href="https://blog.csdn.net/u014740338/article/details/45640225（没说什么类型的文件）" target="_blank" rel="noopener">https://blog.csdn.net/u014740338/article/details/45640225（没说什么类型的文件）</a></p>
</blockquote>
<p>4.构造Merkle Tree</p>
<p>github上的一个项目，还没看完</p>
<blockquote>
<p><a href="https://github.com/quux00/merkle-tree" target="_blank" rel="noopener">https://github.com/quux00/merkle-tree</a></p>
</blockquote>
<h5 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h5><p>主要学习力相关知识，然后搜集了相关的代码。下周任务就是一一实现，并仔细阅读。然后考虑如何将各个小任务整合起来。</p>
  
	</div>
		<footer class="article-footer clearfix">
<div class="article-catetags">


  <div class="article-tags">
  
  <span></span> <a href="/tags/报告/">报告</a><a href="/tags/吴朝捷/">吴朝捷</a>
  </div>

</div>



	<div class="article-share" id="share">
	
	  <div data-url="http://b3434lockchain.gitee.io/2019/06/04/wuchaojie/wuchaojie2/" data-title="吴朝捷_文件处理模块算法 | B3434lockchain" data-tsina="" class="share clearfix">
	  </div>
	
	</div>


</footer>

   	       
	</article>
	
<nav class="article-nav clearfix">
 

<div class="next">
<a href="/2019/06/03/tanjunxi/tanjunxi11/"  title="谭俊熙_Restore客户端界面和接口编写">
 <strong>下一篇：</strong><br/> 
 <span>谭俊熙_Restore客户端界面和接口编写
</span>
</a>
</div>

</nav>

	



</div>  
      <div class="openaside"><a class="navbutton" href="#" title="Show Sidebar"></a></div>

  <div id="toc" class="toc-aside">
  <strong class="toc-title">Contents</strong>
 
 <ol class="toc"><li class="toc-item toc-level-5"><a class="toc-link" href="#实验目的"><span class="toc-number">1.</span> <span class="toc-text">实验目的</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#实验原理"><span class="toc-number">2.</span> <span class="toc-text">实验原理</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#实验内容"><span class="toc-number">3.</span> <span class="toc-text">实验内容</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#总结"><span class="toc-number">4.</span> <span class="toc-text">总结</span></a></li></ol>
 
  </div>

<div id="asidepart">
<div class="closeaside"><a class="closebutton" href="#" title="Hide Sidebar"></a></div>
<aside class="clearfix">

  

  
<div class="tagslist">
	<p class="asidetitle">Tags</p>
		<ul class="clearfix">
		
			
				<li><a href="/tags/周报/" title="周报">周报<sup>23</sup></a></li>
			
		
			
				<li><a href="/tags/谭俊熙/" title="谭俊熙">谭俊熙<sup>11</sup></a></li>
			
		
			
				<li><a href="/tags/苏思捷/" title="苏思捷">苏思捷<sup>5</sup></a></li>
			
		
			
				<li><a href="/tags/学习报告/" title="学习报告">学习报告<sup>5</sup></a></li>
			
		
			
				<li><a href="/tags/卢家豪/" title="卢家豪">卢家豪<sup>5</sup></a></li>
			
		
			
				<li><a href="/tags/报告/" title="报告">报告<sup>5</sup></a></li>
			
		
			
				<li><a href="/tags/苏佳鑫/" title="苏佳鑫">苏佳鑫<sup>4</sup></a></li>
			
		
			
				<li><a href="/tags/冯华文/" title="冯华文">冯华文<sup>4</sup></a></li>
			
		
			
				<li><a href="/tags/周报反馈/" title="周报反馈">周报反馈<sup>2</sup></a></li>
			
		
			
				<li><a href="/tags/吴朝捷/" title="吴朝捷">吴朝捷<sup>2</sup></a></li>
			
		
			
				<li><a href="/tags/黎宁/" title="黎宁">黎宁<sup>1</sup></a></li>
			
		
			
				<li><a href="/tags/笔记/" title="笔记">笔记<sup>1</sup></a></li>
			
		
		</ul>
</div>


</aside>
</div>
    </div>
    <footer><div id="footer" >
	
	
	<div class="social-font" class="clearfix">
		
		
		
		
		
		
		
		
		
		
	</div>
			
		

		<p class="copyright">
		
		</p>
</div>
</footer>
    <script src="/js/jquery-2.0.3.min.js"></script>
<script src="/js/jquery.imagesloaded.min.js"></script>
<script src="/js/gallery.js"></script>
<script src="/js/jquery.qrcode-0.12.0.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){ 
  $('.navbar').click(function(){
    $('header nav').toggleClass('shownav');
  });
  var myWidth = 0;
  function getSize(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
  };
  var m = $('#main'),
      a = $('#asidepart'),
      c = $('.closeaside'),
      o = $('.openaside');
  c.click(function(){
    a.addClass('fadeOut').css('display', 'none');
    o.css('display', 'block').addClass('fadeIn');
    m.addClass('moveMain');
  });
  o.click(function(){
    o.css('display', 'none').removeClass('beforeFadeIn');
    a.css('display', 'block').removeClass('fadeOut').addClass('fadeIn');      
    m.removeClass('moveMain');
  });
  $(window).scroll(function(){
    o.css("top",Math.max(80,260-$(this).scrollTop()));
  });
  
  $(window).resize(function(){
    getSize(); 
    if (myWidth >= 1024) {
      $('header nav').removeClass('shownav');
    }else{
      m.removeClass('moveMain');
      a.css('display', 'block').removeClass('fadeOut');
      o.css('display', 'none');
      
      $('#toc.toc-aside').css('display', 'none');
        
    }
  });
});
</script>

<script type="text/javascript">
$(document).ready(function(){ 
  var ai = $('.article-content>iframe'),
      ae = $('.article-content>embed'),
      t  = $('#toc'),
      ta = $('#toc.toc-aside'),
      o  = $('.openaside'),
      c  = $('.closeaside');
  if(ai.length>0){
    ai.wrap('<div class="video-container" />');
  };
  if(ae.length>0){
   ae.wrap('<div class="video-container" />');
  };
  c.click(function(){
    ta.css('display', 'block').addClass('fadeIn');
  });
  o.click(function(){
    ta.css('display', 'none');
  });
  $(window).scroll(function(){
    ta.css("top",Math.max(140,320-$(this).scrollTop()));
  });
});
</script>


<script type="text/javascript">
$(document).ready(function(){ 
  var $this = $('.share'),
      url = $this.attr('data-url'),
      encodedUrl = encodeURIComponent(url),
      title = $this.attr('data-title'),
      tsina = $this.attr('data-tsina'),
      description = $this.attr('description');
  var html = [
  '<div class="hoverqrcode clearfix"></div>',
  '<a class="overlay" id="qrcode"></a>',
  '<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="article-share-facebook" target="_blank" title="Facebook"></a>',
  '<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="article-share-twitter" target="_blank" title="Twitter"></a>',
  '<a href="#qrcode" class="article-share-qrcode" title="微信"></a>',
  '<a href="http://widget.renren.com/dialog/share?resourceUrl=' + encodedUrl + '&srcUrl=' + encodedUrl + '&title=' + title +'" class="article-share-renren" target="_blank" title="人人"></a>',
  '<a href="http://service.weibo.com/share/share.php?title='+title+'&url='+encodedUrl +'&ralateUid='+ tsina +'&searchPic=true&style=number' +'" class="article-share-weibo" target="_blank" title="微博"></a>',
  '<span title="Share to"></span>'
  ].join('');
  $this.append(html);

  $('.hoverqrcode').hide();

  var myWidth = 0;
  function updatehoverqrcode(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
    var qrsize = myWidth > 1024 ? 200:100;
    var options = {render: 'image', size: qrsize, fill: '#2ca6cb', text: url, radius: 0.5, quiet: 1};
    var p = $('.article-share-qrcode').position();
    $('.hoverqrcode').empty().css('width', qrsize).css('height', qrsize)
                          .css('left', p.left-qrsize/2+20).css('top', p.top-qrsize-10)
                          .qrcode(options);
  };
  $(window).resize(function(){
    $('.hoverqrcode').hide();
  });
  $('.article-share-qrcode').click(function(){
    updatehoverqrcode();
    $('.hoverqrcode').toggle();
  });
  $('.article-share-qrcode').hover(function(){}, function(){
      $('.hoverqrcode').hide();
  });
});   
</script>











<link rel="stylesheet" href="/fancybox/jquery.fancybox.css" media="screen" type="text/css">
<script src="/fancybox/jquery.fancybox.pack.js"></script>
<script type="text/javascript">
$(document).ready(function(){ 
  $('.article-content').each(function(i){
    $(this).find('img').each(function(){
      if ($(this).parent().hasClass('fancybox')) return;
      var alt = this.alt;
      if (alt) $(this).after('<span class="caption">' + alt + '</span>');
      $(this).wrap('<a href="' + this.src + '" title="' + alt + '" class="fancybox"></a>');
    });
    $(this).find('.fancybox').each(function(){
      $(this).attr('rel', 'article' + i);
    });
  });
  if($.fancybox){
    $('.fancybox').fancybox();
  }
}); 
</script>



<!-- Analytics Begin -->





<!-- Analytics End -->

<!-- Totop Begin -->

	<div id="totop">
	<a title="Back to Top"><img src="/img/scrollup.png"/></a>
	</div>
	<script src="/js/totop.js"></script>

<!-- Totop End -->

<!-- MathJax Begin -->
<!-- mathjax config similar to math.stackexchange -->


<!-- MathJax End -->

<!-- Tiny_search Begin -->

<!-- Tiny_search End -->

  </body>
</html>
